const RequireDirectory = require('require-directory');
const Router = require('koa-router');

class InitManager {
  static initCore (app) {
    InitManager.app = app;
    InitManager.initLoadRouters();
  }

  static initLoadRouters () {
    let url = `${process.cwd()}\\app\\api`;
    RequireDirectory(module, url, {
      visit: whenLoadModule
    });

    function whenLoadModule(obj) {
      if (obj instanceof Router) {
        InitManager.app.use(obj.routes())
      }
    }
  }

}

module.exports = InitManager